package com.rd.teacher.jichao.day16;

public class TestSum {

    public static void main(String[] args) {
        int result = 0;
        for (int i = 0; i < 10; i++) {
            SumThread sumThread = new SumThread(i);
            // i = 0   1-10   i*10+1
            // i = 1   11-20  i*10+1
            sumThread.start();
            try {
                sumThread.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            result += sumThread.sum;
        }
        System.out.println(result);
    }

}

class SumThread extends Thread {
    // 循环遍历的索引
    int index = 0;
    int sum = 0;

    public SumThread(int index) {
        this.index = index;
    }

    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            int value = index * 10 + i;
            sum += value;
        }
        System.out.println(getName() + " " + sum);
    }
}